#include "stm32f1xx_hal.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "debug.h"



//extern unsigned short milliscond ;
//extern unsigned char time[6] ;

#define ELOG_LINE_BUF_SIZE                       1024

static char log_buf[ELOG_LINE_BUF_SIZE] = { 0 };


static void elog_port_output(const char *log, size_t size) {
    /* output to terminal */
    printf("%.*s", size, log);
}

void debug_print(unsigned char level, const char *format , ...)
{
    va_list args;
    int fmt_result;
    size_t log_len = 0;
            
    va_start(args, format);
    
    /* package log data to buffer */
    fmt_result = vsnprintf(log_buf, ELOG_LINE_BUF_SIZE, format, args);
    
    /* output converted log */
    if ((fmt_result > -1) && (fmt_result <= ELOG_LINE_BUF_SIZE)) {
        log_len = fmt_result;
    } else {
        log_len = ELOG_LINE_BUF_SIZE;
    }
    
    elog_port_output(log_buf, log_len);
    
    va_end(args);
}


